<template>
  <div>
    <el-card class="box-card" >
     <el-row>
       <el-button style="margin-left: 1200px" type="success" @click="addfund">添加拨款</el-button>
     </el-row>

      <el-table :data="moneylist"
                border style="width: 100%">
        <el-table-column
          fixed
          prop="yearly"
          label="年度"
          width="150">
        </el-table-column>
        <el-table-column
          prop="preFund"
          label="人员经费(万元)"
          width="200">
        </el-table-column>
        <el-table-column
          prop="dutyFund"
          label="公务费(万元)"
          width="200">
        </el-table-column>
        <el-table-column
          prop="businessFund"
          label="业务经费(万元)"
          width="200">
        </el-table-column>
        <el-table-column
          prop="buildFund"
          label="基础建设资金(万元)"
          width="200">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="200">
          <template slot-scope="scope">
            <!--slot-scope="scope" <el-button @click="handleClick(scope.row)" type="text" size="small">查看  </el-button>| -->
            <el-button type="success" round size="small" @click="handleupdate(scope.row.id)">修改 </el-button>
            <el-button type="success" round size="small" @click="handlerdelete(scope.row.id)">删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-row type="flex" justify="center" class="page-row" v-show="page_show">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pagesize"
          layout="total, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-row>
    </el-card>
  </div>
</template>

<script>
  import {post} from "@/utils/api";

  export default {
    props:{
      orgid:Number,
    },
    data() {
      return {
        currentPage:1,
        total:0  ,//一共有多少条数据
        pagesize:2, //每页显示多少条数据  页数等于  total/pagesize
        moneylist:[],
        page_show:true,

      }
    },
    // created() {
    //   this.getListByPage(1)
    // },
    watch:{
      ordid:{
        handler(newvalue){
          this.getListByPage(1,newvalue)
          console.log(this.orgid)
        },
        immediate:true
        // deep:true
      }
    },
    methods: {
      handleupdate(id){
        this.$router.push({path:"fundupdate",query:{id:id}})
        console.log(id)

      },
      async handlerdelete(id){
        await post("money/deletebyid",{id:id})
      },
      async getListByPage(page){
        let res = await post("money/page",{page: page, count: this.pagesize,orgId:this.orgid})
        console.log(res)
        //处理信息
        this.page_show = true
        this.moneylist = res.records

        console.log(this.moneylist)
        this.total = res.total
        console.log(res.total)

      },
      handleCurrentChange(currentPage){
        //当前页码改变时触发
        // console.log(currentPage)
        this.currentPage = currentPage
        this.getListByPage(currentPage,this.orgid)
      },
      addfund(orgid){
        //console.log( typeof this.orgid)
        this.$router.push({name:"fundlist",query:{id:this.orgid}})
      }
    }
  }
</script>
<style></style>
